<template>
  <view class="content">
    <rich-text :nodes="nodes"></rich-text>
	<!-- <text>{{nodes}}</text> -->
  </view>
</template>

<script>
export default {
  data() {
    return {
      nodes: "",
      field: "",
      title: "",
    };
  },
  onLoad(options) {
    let field = options.title;
    this.field = field;
    let title = "服务协议";
	
	switch(field){
		case 'service':
			title = '服务协议'
		break;
		case 'privacy':
			title = '隐私政策'
		break;
		case 'gongyue':
			title = '平台公约'
		break;
		default:
			title = '关于我们'
	}
		
    this.title = title;
    this.init();
  },
  onReady() {
    uni.setNavigationBarTitle({
      title: this.title,
    });
  },
  methods: {
    init() {
		if(this.field === 'gongyue'){
			this.$http
			  .post("api/index/getGongyue", {
			    field: this.field,
			  })
			  .then((res) => {
				const replaced = res.replace(/\t/g, "    ").replace(/\n/g, "<br>");
				this.nodes = replaced
			  });
		}else{
			this.$http
			  .post("api/user/config", {
			    field: this.field,
			  })
			  .then((res) => {
			    this.nodes = res;
			});
		}
    },
  },
};
</script>

<style>
.content {
  font-size: 13px;
  line-height: 22px;
  padding: 12px;
}
</style>
